#!/usr/bin/env python3
# -*- coding:utf-8 -*-


"""
时间类
"""

import time

from src.common.log import logger


def cal_time(func):
    """
    函数计时
    :param func:
    :return:
    """

    def wrapper(*args, **kwargs):
        """
        wrapper
        """
        ts = time.time()
        result = func(*args, **kwargs)
        te = time.time()
        logger.debug("[TIME] %s time elapsed: %s secs." % (func.__name__, te - ts))
        return result

    return wrapper


def async_cal_time(func):
    """
    函数计时
    :param func:
    :return:
    """

    async def wrapper(*args, **kwargs):
        """
        wrapper
        """
        ts = time.time()
        result = await func(*args, **kwargs)
        te = time.time()
        logger.debug("[TIME] %s time elapsed: %s secs." % (func.__name__, te - ts))
        return result

    return wrapper
